package com.Final.hj;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class TaskJkes extends AppCompatActivity {

    private FloatingActionButton float_button;
    private DrawerLayout task_drawer_menu;
    private NavigationView task_nav_view;
    private RecyclerView task_recyclerView;
    private LinearLayoutManager linearLayoutManager;

    private List<TaskJesksData> taskDatas = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.task_jesks);
        initView();
        initData();

        task_recyclerView.setLayoutManager(linearLayoutManager);
        task_recyclerView.setAdapter(new TaskJesksAdapter(this, taskDatas));

    }

    //初始化变量
    public void initView(){

        float_button = (FloatingActionButton) findViewById(R.id.task_jesk_float_button);
        task_drawer_menu = (DrawerLayout) findViewById(R.id.drawerLayout_wrap);
        task_nav_view = (NavigationView) findViewById(R.id.task_nav_view);
        task_recyclerView = (RecyclerView) findViewById(R.id.task_recyclerView);

        linearLayoutManager = new LinearLayoutManager(TaskJkes.this);

        //设置默认第一项选中
        task_nav_view.setCheckedItem(R.id.task_live);

        task_nav_view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                task_drawer_menu.closeDrawers();
                return true;
            }
        });

        //为悬浮按钮绑定事件
        float_button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                //点击出现左侧菜单栏
                task_drawer_menu.openDrawer(Gravity.START);
            }
        });
    }
    //初始化一些数据
    public void initData(){
        for (int i = 0; i< 10; i++){
            TaskJesksData t1 = new TaskJesksData("123", String.valueOf(R.drawable.nine), "车神-黄杰",
                    "如果你得罪了老板，失去的只是一份工作；如果你得罪了客户，失去的不过是一份订单；" +
                            "是的，世上只有一个人可以得罪：你给她脸色看，你冲她发牢骚，你大声顶撞她，" +
                            "甚至当 着她的面摔碗，她都不会记恨你，原因很简单，因为她是你的母亲。",
                    "99", "2019-06-26 23:45");
            taskDatas.add(t1);
            taskDatas.add(t1);
            taskDatas.add(t1);
            taskDatas.add(t1);
            taskDatas.add(t1);
        }
    }
}
